
package com.compuvest.amazon

import groovy.xml.StreamingMarkupBuilder

import javax.servlet.ServletConfig

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

class AmazonSendTest extends HttpServlet {

    def void init(ServletConfig config) {
	super.init(config)
    }

    def void processRequest(request, response) {

        def result = new StringBuilder()
        result << makeXML()

        response.setContentType("text/xml;charset=UTF-8")
        def out = response.getWriter()
        try {
            out.print(result.toString())
        }
        finally {
            out.close()
        }
    }

    def makeXML() {

        def xml = new StreamingMarkupBuilder().bind {
            orders {
                order(amazonNo: "103-9315926-4367477", compuvestNo: "") {
                    email("vlad@compuvest.com")
                    name("Vlad Goncharov")
                    address1("Lind Ave")
                    address2("Aprtment 500")
                    address3("")
                    city("Renton")
                    state("Texas")
                    country("USA")
                    zipcode("98055-1234")
                    phone("206-333-4444")
                }
            }
        }

        return xml
    }

    def void doGet(HttpServletRequest request, HttpServletResponse response) {
        processRequest(request, response)
    }
    def void doPost(HttpServletRequest request, HttpServletResponse response) {
        processRequest(request, response)
    }
    String getServletInfo() {
        return "AmazonSendTest"
    }
    def void destroy() {
    }
}
